package com.itic.mall.mobile.users.livingRate;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.annotation.CheckLogin;
import com.itic.appbase.framework.type.ConsumeMoneyType;
import com.itic.appbase.framework.type.TaxCompany;
import com.itic.appbase.framework.type.UserShareType;
import com.itic.appbase.framework.type.UserType;
import com.itic.appbase.framework.utils.HttpRequestUtils;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.mobile.share.LinkVo;
import com.itic.mall.mobile.users.livingRate.entity.LivingRateResultVo;
import com.itic.mall.system.finance.makeMoney.persistence.model.FinanceUserMakeMoney;
import com.itic.mall.system.finance.makeMoney.persistence.model.FinanceUserMakeMoneyExample;
import com.itic.mall.system.finance.makeMoney.service.FinanceUserMakeMoneyService;
import com.itic.mall.system.orders.detail.persistence.model.OrdersDetail;
import com.itic.mall.system.orders.detail.service.OrdersDetailService;
import com.itic.mall.system.orders.item.persistence.model.OrdersItem;
import com.itic.mall.system.orders.item.service.OrdersItemService;
import com.itic.mall.system.orders.orderJD.persistence.model.OrderJD;
import com.itic.mall.system.orders.orderJD.service.OrderJDService;
import com.itic.mall.system.orders.orderJDProject.persistence.model.OrdersJDProduct;
import com.itic.mall.system.orders.orderJDProject.service.OrdersJDProductService;
import com.itic.mall.system.project.interest.persistence.model.Interest;
import com.itic.mall.system.project.interest.service.InterestService;
import com.itic.mall.system.project.livingRate.service.LivingRateService;
import com.itic.mall.system.users.giveMoney.persistence.model.UsersGiveMoney;
import com.itic.mall.system.users.giveMoney.service.UsersGiveMoneyService;
import com.itic.mall.system.users.shareLog.service.UsersShareLogService;
import com.itic.mall.system.users.userHelp.persistence.model.UsersHelp;
import com.itic.mall.system.users.userHelp.service.UsersHelpService;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMall;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMallExample;
import com.itic.mall.system.users.usersmall.service.UsersMallService;

import net.sf.json.JSONObject;



@Controller
@RequestMapping(value="/mobile/user/living")
public class UserLivingRateInterface extends BaseMobileInterface{
	
	@Autowired
	private LivingRateService livingRateService;
	
	@Autowired
	private UsersMallService usersMallService;
	
	@Autowired
	private OrdersDetailService ordersDetailService;
	
	@Autowired
	private FinanceUserMakeMoneyService financeUserMakeMoneyService;
	
	@Autowired
	private OrdersItemService ordersItemService;
	
	@Autowired
	private OrderJDService orderJDService;
	
	@Autowired
	private OrdersJDProductService ordersJDProductService;
	
	@Autowired
	private UsersHelpService usersHelpService;
	
	@Autowired
	private InterestService interestService;
	
	@Autowired
	private UsersGiveMoneyService usersGiveMoneyService;
	
	@Autowired
	private UsersShareLogService usersShareLogService;
	
	
	@RequestMapping(value="/index")
	@ResponseBody
	@CheckLogin
	public Map<String,Object> index( HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	Map<String, Object> data =  this.ordersDetailService.getUserTotalCousume(usersMall.getId());
	    	double money = usersMall.getMoney()==null?0:usersMall.getMoney();
	    	data.put("balance", money);
	    	LivingRateResultVo livingRateResultVo = this.livingRateService.calUserLivingRate(usersMall);
	    	data.put("yearRate", livingRateResultVo.getYearRate());
	    	double totalMoney = this.financeUserMakeMoneyService.getUserTotalMakeMoney(usersMall.getId());
	    	data.put("totalMoney", totalMoney);
	    	double livingMoney = usersMall.getLivingMoney()==null?0:usersMall.getLivingMoney();
	    	String todayMoney = this.livingRateService.calLivingMoney(Double.toString(livingRateResultVo.getYearRate()), Double.toString(livingMoney));
	    	//double todayMoney = this.financeUserMakeMoneyService.getUserTodayMakeMoney(usersMall.getId());
	    	data.put("todayMoney", Double.parseDouble(todayMoney));
	    	List<UsersGiveMoney> usersGiveMoneys = this.usersGiveMoneyService.findMoneyByUserId(usersMall.getId());
	    	if(usersGiveMoneys.isEmpty()) {
	    		data.put("state", 0);
	    		data.put("image", "https://uhuijia-1254600872.cos.ap-beijing.myqcloud.com/c9db4df6-c7a6-444c-90cf-d64f0ebfce42.png");
	    		this.usersGiveMoneyService.userRegistMoney(usersMall, 200, 200);
	    	}else
	    		data.put("state", 1);
	    	errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	       	resultMap.put(DATA, data);
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "index", e.toString(),"APP进入生钱页面接口信息",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/yearRate/detail")
	@ResponseBody
	@CheckLogin
	public Map<String,Object> yearRateDetail( HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	LivingRateResultVo livingRateResultVo = this.livingRateService.calUserLivingRate(usersMall);
	    	errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	       	resultMap.put(DATA, livingRateResultVo);
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "index", e.toString(),"APP进入利率详情接口信息",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	@RequestMapping(value="/livingMoney/log")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> livingMoneyLog(HttpServletRequest request , HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	FinanceUserMakeMoneyExample example = new FinanceUserMakeMoneyExample();
	    	this.handlePageQueryDefault(request, example);
	    	List<FinanceUserMakeMoney> financeUserMakeMoneys = this.financeUserMakeMoneyService.getUserMakeMoneyLog(usersMall.getId(), example);
	    	List<Map<String, Object>> dataList = new ArrayList<>();
	    	for(FinanceUserMakeMoney makeMoney : financeUserMakeMoneys) {
	    		Map<String, Object> data = new HashMap<>();
	    		data.put("money", makeMoney.getAmount());
	    		data.put("info", "友惠钱包利息");
	    		data.put("type", "yh");
	    		data.put("createTime",makeMoney.getCreateTime());
	    		data.put("sign","0");
	    		dataList.add(data);
	    	}
	    	errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	       	resultMap.put(DATA, dataList);
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "livingMoneyLog", e.toString(),"APP进入生钱列表接口信息",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/consume/log")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> consumeMoneyLog(HttpServletRequest request , HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	UsersMallExample example = new UsersMallExample();
		
			this.handlePageQueryDefault(request, example);
			int start = example.getPage().getRecordNow();
			int length = example.getPage().getPageSize();
			List<Map<String,Object>> data  = this.usersMallService.findConsumeLog(usersMall.getId(), start, length);
	    	for(Map<String, Object> map : data) {
	    		String type = (String) map.get("type");
	    		ConsumeMoneyType consumeMoneyType = ConsumeMoneyType.getConsumeMoneyType(type);
	    		map.put("info", consumeMoneyType.getName());
	    		map.put("type", consumeMoneyType.getType());
	    		map.put("sign", "1");
	    	}
			errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	       	resultMap.put(DATA, data);
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "consumeMoneyLog", e.toString(),"花钱列表",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	/**
	 * 消费详情页
	 * @param request
	 * @param response
	 * @param orderNo
	 * @param type
	 * @return
	 */
	@RequestMapping(value="/consume/detail")
	@ResponseBody
	public Map<String, Object> consumeMoneyDetail(HttpServletRequest request , HttpServletResponse response,String orderNo,String type){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    Map<String, Object> data = new HashMap<String,Object>();
	    try{
	    	if(StringUtils.isNoneBlank(orderNo,type)) {
	    		ConsumeMoneyType consumeMoneyType = ConsumeMoneyType.getConsumeMoneyType(type);
	    		data.put("type", consumeMoneyType.getType());
	    		List<Map<String, Object>> goodsData = new ArrayList<>();
	    		int totalCount = 0;
	    		switch (consumeMoneyType) {
	    		case yh:
	    			OrdersDetail ordersDetail =  this.ordersDetailService.getOrdersDetailByOrderNo(orderNo);
	    			orderNo = ordersDetail.getOrderNo();
	    			Date submitDate = ordersDetail.getCreateTime();
	    			data.put("orderNo", orderNo);
	    			data.put("submitDate", submitDate);
	    			List<OrdersItem> ordersItems = this.ordersItemService.getOrderItemsByOrderNo(orderNo);
	    			for(OrdersItem ordersItem : ordersItems) {
	    				Map<String, Object> goodData = new HashMap<String,Object>();
	    				goodData.put("goodName", ordersItem.getGoodsName());
	    				goodData.put("goodImg", ordersItem.getGoodsImg());
	    				goodData.put("count", ordersItem.getCount());
	    				goodData.put("money", ordersItem.getActualPay());
	    				totalCount+=ordersItem.getCount();
	    				goodsData.add(goodData);
	    			}
	    			data.put("totalMoney", ordersDetail.getActualPay());
	    			break;
	    		case jd:
	    			OrderJD orderJD = this.orderJDService.getOrderJDByOrderNum(orderNo);
	    			data.put("orderNo", orderJD.getOrderNum());
	    			data.put("submitDate", orderJD.getOrderDate());
	    			data.put("totalMoney", orderJD.getOrderTotalMoney());
	    			List<OrdersJDProduct> ordersJDProducts = this.ordersJDProductService.getOrdersJdProduct(orderJD.getId());
	    			for(OrdersJDProduct ordersJDProduct : ordersJDProducts) {
	    				Map<String, Object> goodData = new HashMap<String,Object>();
	    				goodData.put("goodName", ordersJDProduct.getSkuName());
	    				goodData.put("goodImg", ordersJDProduct.getSkuImgUrl());
	    				goodData.put("count", ordersJDProduct.getSkuNum());
	    				goodData.put("money", ordersJDProduct.getSkuPrice());
	    				totalCount+=Integer.parseInt(ordersJDProduct.getSkuNum());
	    				goodsData.add(goodData);
	    			}
	    			break;
	    		}
	    		data.put("totalCount", totalCount);
	    		data.put("goods", goodsData);
	    		errorCode = SUCCESS_ERROR_CODE;
	    		errorMsg = SUCCESS_ERROR_MSG;
	    		resultMap.put(DATA, data);
	    	}else {
	    		errorCode = PARAM_ERROR_CODE;
	    		errorMsg = PARAM_ERROR_MSG;
	    	}
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "consumeMoneyDetail", e.toString(),"花钱详情",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/play")
	@ResponseBody
	public Map<String, Object> makeMoneyPlay(HttpServletRequest request , HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<FinanceUserMakeMoney> financeUserMakeMoneys = this.financeUserMakeMoneyService.findUserMakeYesterday();
	 	   	List<Map<String, Object>> dataList = new ArrayList<>();
	    	int i =0;
	 	   	for(FinanceUserMakeMoney makeMoney : financeUserMakeMoneys) {
	    		Map<String, Object> data = new HashMap<String,Object>();
	    		UsersMall usersMall = this.usersMallService.get(makeMoney.getUserId());
	    		data.put("nickName", usersMall.getUserNickName());
	    		data.put("userHead", usersMall.getUserHeadImg());
	    		data.put("money", makeMoney.getAmount());
	    		dataList.add(data);
	    		i++;
	    		if(i>=10)
	    			break;
	    	}
	    	errorCode = SUCCESS_ERROR_CODE;
    		errorMsg = SUCCESS_ERROR_MSG;
    		resultMap.put(DATA, dataList);
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "consumeMoneyDetail", e.toString(),"花钱详情",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/money")
	@ResponseBody
	public Map<String, Object> livingMoney(HttpServletRequest request,HttpServletResponse response) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	List<UsersMall> usersMalls = this.usersMallService.findUsersMallByType(UserType.user);
	    	for(UsersMall usersMall : usersMalls) {
	    		try {
	    			this.usersMallService.livingMoney(usersMall);
				} catch (Exception e) {
					logException("UserLivingRateInterface", "livingMoney", e.toString(),"用户生钱定时器",e);
				}
	    	}
	    	errorCode = SUCCESS_ERROR_CODE;
    		errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "consumeMoneyDetail", e.toString(),"花钱详情",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	@RequestMapping(value="/jd/remainCommission")
	@ResponseBody
	public Map<String, Object> calJDLivingMoney(HttpServletRequest request,HttpServletResponse response,String userId,String yunId,String commission,Integer count ) {
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.usersMallService.get(userId);
	    	if(usersMall!=null && !UserType.isYDZ(usersMall.getType())) {
	    		UsersMall yunUser = this.usersMallService.get(yunId);
	    		double remainMoney = this.payUserlogService.calRemainCommission(yunUser,commission,TaxCompany.jd, count);
	    		double livingMoney = usersMall.getLivingMoney()==null?0:usersMall.getLivingMoney();
	    		livingMoney += remainMoney;
	    		usersMall.setLivingMoney(livingMoney);
	    		this.usersMallService.edit(usersMall);
	    	}
	    	errorCode = SUCCESS_ERROR_CODE;
    		errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "calJDRemainCommission", e.toString(),"京东确认收货时计算用户生息本金",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	@RequestMapping(value="/share/myYearRate")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> shareMyYearRate(HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	String url = "http://file.jhjvip.cn:8888/image-server/uploadImage/oss/shareYearRate";
	    	StringBuffer params = new StringBuffer();
	    	params.append("nickName=");
	    	params.append(usersMall.getUserNickName());
	    	params.append("&url=");
	    	params.append("http://jxyh.huifakeji.com/Uc/fuelling.html?userId=").append(usersMall.getId());
	    	params.append("&userHeadImage=");
	    	params.append(usersMall.getUserHeadImg());
	    	params.append("&consume=");
	    	params.append("100");
	    	params.append("&yearRate=");
	    	LivingRateResultVo livingRateResultVo = this.livingRateService.calUserLivingRate(usersMall);
	    	params.append(livingRateResultVo.getYearRate());
	    	params.append("&dayMoney=");
	    	params.append("0.0056");
	    	String result = HttpRequestUtils.sendPost(url, params.toString());
	    	JSONObject fromObject = JSONObject.fromObject(result);
			String resultRemote = fromObject.getString("errorCode");
			if( "10000".equals(resultRemote)){
				resultMap.put(DATA, fromObject.getString("data"));
			}
	    	errorCode = SUCCESS_ERROR_CODE;
    		errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "shareMyYearRate", e.toString(),"晒年化率",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/help/index")
	@ResponseBody
	public Map<String, Object> helpIndex(HttpServletRequest request,HttpServletResponse response,String userId,String unionId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.usersMallService.get(userId);
	    	if(usersMall!=null) {
	    		Map<String, Object> data = new HashMap<String,Object>();
	    		LivingRateResultVo livingRateResultVo = this.livingRateService.calUserLivingRate(usersMall);
	    		data.put("yearRate", livingRateResultVo.getYearRate());
	    		data.put("userHeadImg",usersMall.getUserHeadImg());
	    		data.put("nickName",usersMall.getUserNickName());
	    		data.put("consume",100.20);
	    		data.put("dayMoney", 0.0056);
	    		List<UsersHelp> usersHelps = this.usersHelpService.findHelpUserByUnionId(unionId, userId);
	    		if(usersHelps.isEmpty())
	    			data.put("state","0");
	    		else
	    			data.put("state","1");
	    		usersHelps = this.usersHelpService.findHelpUserByUserId(userId);
	    		List<Map<String, Object>> usersHelp = new ArrayList<>();
	    		double totalRate = 0;
	    		for(UsersHelp userHelp : usersHelps) {
	    			Map<String, Object>  user = new HashMap<>();
	    			user.put("nickName", userHelp.getName());
	    			user.put("rate", userHelp.getRate());
	    			usersHelp.add(user);
	    			totalRate+=userHelp.getRate()==null?0:userHelp.getRate();
	    		}
	    		data.put("usersHelp", usersHelp);
	    		data.put("totalUser", usersHelp.size());
	    		data.put("totalRate", totalRate);
	    		resultMap.put(DATA, data);
	    		errorCode = SUCCESS_ERROR_CODE;
	    		errorMsg = SUCCESS_ERROR_MSG;
	    	}
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "helpIndex", e.toString(),"助力首页",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/help")
	@ResponseBody
	public Map<String, Object> help(HttpServletRequest request,HttpServletResponse response,String userId,String unionId ,String name){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	if(StringUtils.isNoneBlank(userId,name,unionId)) {
	    		List<UsersHelp> usersHelps = this.usersHelpService.findHelpUserByUnionId(unionId);
	    		if(usersHelps.isEmpty()) {
	    			UsersMall usersMall = this.usersMallService.get(userId);
	    			if(usersMall!=null) {
	    				double rate = this.usersHelpService.calHelpRate();
	    				String result = this.usersHelpService.addUserHelp(userId, name, unionId, rate);
	    				if(SUCCESS.equals(result)) {
	    					resultMap.put(DATA, rate);
		    				errorCode = SUCCESS_ERROR_CODE;
		    				errorMsg = SUCCESS_ERROR_MSG;
	    				}
	    			}
	    		}else{
	    			errorCode = USER_ALREADY_HELP_ERROR_CODE;
    				errorMsg = USER_ALREADY_HELP_ERROR_MSG;
	    		}
	    	}
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "help", e.toString(),"为他助理",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/share/invite")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> shareInvite(HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	String url = "http://wap.uhuijia.com.cn/money/html/draw.html?userId="+usersMall.getId();
	    	String title = "网购花掉的钱存账户赚利息";
	    	String content = "用友惠家去京东购买东西，花掉的钱等于存进余额宝每天赚的利息!";
	    	LinkVo linkVo = new LinkVo();
	    	linkVo.setContent(content);
	    	linkVo.setImgUrl("https://uhuijia-1254600872.cos.ap-beijing.myqcloud.com/c169deea-8424-4715-8bb3-0636c31292ee.png");
	    	linkVo.setTitle(title);
	    	linkVo.setUrl(url);
	    	this.usersShareLogService.addShareLog(UserShareType.App, null, usersMall);
			resultMap.put(DATA, linkVo);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "shareInvite", e.toString(),"分享邀请提高年利率",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	@RequestMapping(value="/share/invite/index")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> shareInviteIndex(HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	UsersMallExample example = new UsersMallExample();
			this.handlePageQueryDefault(request, example);
			int start = example.getPage().getRecordNow();
			int length = example.getPage().getPageSize();
			List<Map<String, Object>> dataList = this.financeUserMakeMoneyService.findInviteMoneyByParams(usersMall.getId(), start, length);;
			int count = this.financeUserMakeMoneyService.findInviteMoneyCountByParams(usersMall.getId());
			String isMore = this.isMore(request, count);
			Map<String , Object> dataMap = new HashMap<>();
			dataMap.put("total",count);
			dataMap.put("list", dataList);
			dataMap.put("isMore", isMore);
			List<String> rules = new ArrayList<>();
	    	rules.add("1.好友通过扫描您分享海报上的二维码，进入友惠家网页领取新人红包，并在24小时内下载友惠家，即算您成功邀请。");
			rules.add("2.好友邀请关系一旦建立是长期有效且不可更改的，能为您持续的带来奖励，建议您尽快邀请好友一起用友惠家。");
			rules.add("3.禁止通过作弊手段骗取奖励，一经发现，将取消奖励并酌情处罚。");
			rules.add("4.本活动从2017年12月08号开始生效，最终解释权归友惠家所有。");
			dataMap.put("rules", rules);
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "shareInviteIndex", e.toString(),"分享邀请index",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/receive/index")
	@ResponseBody
	public Map<String, Object> receiveIndex(HttpServletRequest request,HttpServletResponse response,String userId){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.usersMallService.get(userId);
			Map<String , Object> dataMap = new HashMap<>();
			dataMap.put("userNickName", usersMall.getUserNickName());
			dataMap.put("money", 200);
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "receiveIndex", e.toString(),"领取Index",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/HB/index")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> receiveIndex(HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	String url = "http://file.jhjvip.cn:8888/image-server/uploadImage/oss/shareYearRateHB";
	    	StringBuffer params = new StringBuffer();
	    	params.append("nickName=");
	    	params.append(usersMall.getUserNickName());
	    	params.append("&url=");
	    	params.append("http://wap.uhuijia.com.cn/index.html#/invitedownload");
	    	params.append("&userHeadImage=");
	    	params.append(usersMall.getUserHeadImg());
	    	params.append("&consumeCount=");
	    	params.append("100");
	    	params.append("&dayMoney=");
	    	params.append("0.0056");
	    	String result = HttpRequestUtils.sendPost(url, params.toString());
	    	JSONObject fromObject = JSONObject.fromObject(result);
			String resultRemote = fromObject.getString("errorCode");
			Map<String,Object> data = new HashMap<>();
			if( "10000".equals(resultRemote)){
				data.put("image", fromObject.getString("data"));
			}
			List<String> rules = new ArrayList<>();
			rules.add("1.好友通过扫描您分享海报上的二维码，进入友惠家网页领取新人红包，并在24小时内下载友惠家，即算您成功邀请。");
			rules.add("2.好友邀请关系一旦建立是长期有效且不可更改的，能为您持续的带来奖励，建议您尽快邀请好友一起用友惠家。");
			rules.add("3.禁止通过作弊手段骗取奖励，一经发现，将取消奖励并酌情处罚。");
			rules.add("4.本活动从2017年12月08号开始生效，最终解释权归友惠家所有。");
			data.put("rules", rules);
			resultMap.put(DATA, data);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "receiveIndex", e.toString(),"领取Index",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/interest/index")
	@ResponseBody
	public Map<String, Object> interestIndex(HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	Map<String, Object> data = new HashMap<>();
	    	Interest interest = this.interestService.getInterest();
	    	data.put("totalProfit", interest.getTotalProfit());
	    	data.put("totalPeople", interest.getTotalPeople());
	    	data.put("totalRedMoney", interest.getTotalRedMoney());
	    	data.put("totalUserProfit", interest.getTotalUserProfit());
	    	List<String> rules = new ArrayList<>();
	    	rules.add("1.好友通过扫描您分享海报上的二维码，进入友惠家网页领取新人红包，并在24小时内下载友惠家，即算您成功邀请。");
			rules.add("2.好友邀请关系一旦建立是长期有效且不可更改的，能为您持续的带来奖励，建议您尽快邀请好友一起用友惠家。");
			rules.add("3.禁止通过作弊手段骗取奖励，一经发现，将取消奖励并酌情处罚。");
			rules.add("4.本活动从2017年12月08号开始生效，最终解释权归友惠家所有。");
			data.put("rules", rules);
	    	resultMap.put(DATA, data);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "receiveIndex", e.toString(),"领取Index",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	@RequestMapping(value="/share/interest")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> shareInterest(HttpServletRequest request,HttpServletResponse response){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	UsersMall usersMall = this.CurUsersMall(request);
	    	String url = "http://wap.uhuijia.com.cn/money/html/magical.html";
	    	String title = "我每天用购物的钱在神奇APP赚钱-友惠家";
	    	String content = "我用友惠家上京东淘宝天猎购物，友惠家每天给我发现金，你也来试试吧";
	    	LinkVo linkVo = new LinkVo();
	    	linkVo.setContent(content);
	    	linkVo.setImgUrl("https://uhuijia-1254600872.cos.ap-beijing.myqcloud.com/53529475-c579-45ba-acc6-44be6906723b.png");
	    	linkVo.setTitle(title);
	    	linkVo.setUrl(url);
	    	this.usersShareLogService.addShareLog(UserShareType.App, null, usersMall);
	    	resultMap.put(DATA, linkVo);
	    	errorCode = SUCCESS_ERROR_CODE;
	    	errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){ 
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("UserLivingRateInterface", "shareInterest", e.toString(),"领取Index",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
}
